package com.example.finalproject.experiments.wechat

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.example.finalproject.R
import com.example.finalproject.ui.theme.FinalProjectTheme

class PersonalInfoActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            FinalProjectTheme {
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    PersonalInfoScreen(intent.getStringExtra("friendName"))
                }
            }
        }
    }
}

@Composable
fun PersonalInfoScreen(friendName: String?) {
    val isPersonalProfile = friendName == null
    val name = friendName ?: "我的资料"

    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(16.dp),
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        Image(
            painter = painterResource(id = android.R.drawable.btn_star),
            contentDescription = "Profile Picture",
            modifier = Modifier
                .size(120.dp)
                .padding(16.dp)
        )

        Text(
            text = name,
            style = MaterialTheme.typography.titleLarge,
            fontWeight = FontWeight.Bold,
            modifier = Modifier.padding(vertical = 16.dp)
        )

        InfoCard("微信号", "wxid_123456")
        InfoCard("地区", "北京")
        InfoCard("个性签名", "这是一条个性签名")

        if (isPersonalProfile) {
            Spacer(modifier = Modifier.weight(1f))
            Button(
                onClick = { /* 编辑资料功能 */ },
                modifier = Modifier.padding(vertical = 16.dp)
            ) {
                Text("编辑资料")
            }
        }
    }
}

@Composable
fun InfoCard(label: String, value: String) {
    Card(
        modifier = Modifier
            .fillMaxWidth()
            .padding(vertical = 8.dp),
        elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
    ) {
        Row(
            modifier = Modifier
                .padding(16.dp)
                .fillMaxWidth(),
            horizontalArrangement = Arrangement.SpaceBetween
        ) {
            Text(text = label)
            Text(text = value)
        }
    }
}